#ifndef __MYSQLDATABASE_H__
#define __MYSQLDATABASE_H__

#include "stdDataBase.h"
#include <mysql/mysql.h>
#include <iostream>
#include <chrono>

class MysqlDataBase : public StdDataBase
{
public:
    MysqlDataBase(const std::string &host, const std::string &user, const std::string &passwd);
    ~MysqlDataBase();

public:
    /* 连接数据库 */
    bool connectDB(const std::string &connStr) override;

    /* 执行Sql语句(exec) */
    bool executeSql(const std::string &sql) override;

    /* 查询Sql语句(select) */
    QueryResult querySql(const std::string &sql) override;

    /* 关闭数据库连接 */
    void close() override;

    /* 刷新时间戳 */
    void refreshAliveTime();

    /* 获取存活时间 */
    long getAliveTime();

private:
    MYSQL *m_conn;
    std::string m_host;
    std::string m_user;
    std::string m_passwd;

    /* 备份一下当前时间 */
    std::chrono::steady_clock::time_point m_backUpCurrentTime;
};

#endif // __MYSQLDATABASE_H__